
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>快速开始 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="install.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    入门
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.2.1" data-path="quick-start.html">
            
                <a href="quick-start.html">
            
                    
                    快速开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="install.html">
            
                <a href="install.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    配置
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../config/global-config.html">
            
                <a href="../config/global-config.html">
            
                    
                    全局配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../config/datasource-config.html">
            
                <a href="../config/datasource-config.html">
            
                    
                    数据源配置
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    核心功能
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../core/config-database.html">
            
                <a href="../core/config-database.html">
            
                    
                    添加数据源
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../core/generic-crud.html">
            
                <a href="../core/generic-crud.html">
            
                    
                    通用 CRUD
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../core/accessor-api.html">
            
                <a href="../core/accessor-api.html">
            
                    
                    Accessor API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >快速开始</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5FEB;&#x901F;&#x5F00;&#x59CB;">&#x5FEB;&#x901F;&#x5F00;&#x59CB;</h1>
<h2 id="&#x7B80;&#x5355;&#x793A;&#x4F8B;">&#x7B80;&#x5355;&#x793A;&#x4F8B;</h2>
<blockquote>
<p>&#x5047;&#x8BBE;&#x6709;&#x4E00;&#x5F20; User &#x8868;&#xFF0C;&#x4EE5;&#x53CA;&#x5176;&#x5BF9;&#x5E94;&#x7684;&#x5B9E;&#x4F53;&#x7C7B; User</p>
</blockquote>
<p>&#x9996;&#x5148;&#x8981;&#x914D;&#x7F6E;&#x6570;&#x636E;&#x5E93;</p>
<pre><code class="lang-java">AccessorFactoryBuilder builder = <span class="hljs-keyword">new</span> AccessorFactoryBuilder();
DatabaseConfig config = <span class="hljs-keyword">new</span> DatabaseConfig(url, user, pass).setMaxWait(<span class="hljs-number">3000</span>).setTag(AccessorFactory.DEFAULT_TAG);
builder.addDatabse(config);
builder.build();
</code></pre>
<pre><code class="lang-java"><span class="hljs-meta">@Table</span>(<span class="hljs-string">&quot;user&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> </span>{
    <span class="hljs-meta">@Id</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">long</span> id;
    <span class="hljs-meta">@Column</span>(<span class="hljs-string">&quot;userName&quot;</span>)
    <span class="hljs-keyword">private</span> String userName;
    <span class="hljs-meta">@Column</span>
    <span class="hljs-keyword">private</span> String password;
    <span class="hljs-meta">@Column</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> age;

    <span class="hljs-comment">// setter and getter</span>

}
</code></pre>
<blockquote>
<p>&#x624B;&#x5199; SQL&#xFF0C;&#x624B;&#x52A8;&#x586B;&#x5145;&#x53C2;&#x6570;&#xFF08;&#x7075;&#x6D3B;&#xFF0C;&#x7F16;&#x5199;&#x590D;&#x6742; SQL&#xFF09;</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-comment">// &#x63D2;&#x5165;</span>
String sql = <span class="hljs-string">&quot;INSERT INTO user VALUES (?, ?, ?, ?)&quot;</span>;
Object[] params = {KeyGenerateUtil.generateId(), <span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>, <span class="hljs-string">&quot;123456&quot;</span>, <span class="hljs-number">20</span>};
<span class="hljs-comment">// &#x66F4;&#x5C11;&#x7684;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; A.update(sql, params);</span>
<span class="hljs-keyword">int</span> row = AccessorFactory.accessor().update(sql, params);

<span class="hljs-comment">// &#x5220;&#x9664;</span>
String sql = <span class="hljs-string">&quot;DELETE FROM user WHERE id = ?&quot;</span>;
row = A.update(sql, id);

<span class="hljs-comment">// &#x66F4;&#x65B0;</span>
String sql = <span class="hljs-string">&quot;UPDATE user SET userName = ? WHERE id = ?&quot;</span>;
Object[] params = {id};
row = A.createUpdate(sql)
  .bind(userName)
  .bindArray(params)
  .execute();

<span class="hljs-comment">// &#x67E5;&#x8BE2;&#x5355;&#x6761;&#x8BB0;&#x5F55;</span>
String sql = <span class="hljs-string">&quot;SELECT * FROM user WHERE id = ?&quot;</span>;
Object[] params = {id};
<span class="hljs-comment">// &#x8BE5;&#x65B9;&#x6CD5;&#x4E2D;&#x7684;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4E0D;&#x4E00;&#x5B9A;&#x662F;&#x4F7F;&#x7528; @Table &#x6CE8;&#x89E3;&#x7684;&#x7C7B;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x4EFB;&#x610F; Java Bean</span>
User user = A.query(sql, params).one(User.class);
<span class="hljs-comment">// &#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x5C06;&#x67E5;&#x8BE2;&#x7684;&#x7ED3;&#x679C;&#x5C01;&#x88C5;&#x5230;&#x4E00;&#x4E2A; Map &#x4E2D;</span>
<span class="hljs-comment">// ResultMap map = A.query(sql, params).oneMap();</span>

<span class="hljs-comment">// &#x67E5;&#x8BE2;&#x591A;&#x6761;&#x8BB0;&#x5F55;</span>
String sql = <span class="hljs-string">&quot;SELECT * FROM user&quot;</span>;
List&lt;User&gt; users = A.query(sql).list(User.class);
</code></pre>
<blockquote>
<p>&#x6CE8;&#x89E3;</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-comment">// &#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x62BD;&#x8C61;&#x7C7B;</span>
<span class="hljs-meta">@Mapper</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">UserMapper</span> </span>{

    <span class="hljs-meta">@Update</span>(<span class="hljs-string">&quot;INSERT INTO user VALUES (${user.id}, ${user.userName}, ${user.password}, ${user.age})&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">insert</span><span class="hljs-params">(@Bind(<span class="hljs-string">&quot;user&quot;</span>)</span> User user)</span>;

    <span class="hljs-meta">@Select</span>(<span class="hljs-string">&quot;SELECT * FROM user WHERE id = ${id}&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> User <span class="hljs-title">select</span><span class="hljs-params">(@Bind(<span class="hljs-string">&quot;id&quot;</span>)</span> <span class="hljs-keyword">long</span> userId)</span>;

}

<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
UserMapper mapper = A.getMapper(UserMapper.class);
mapper.insert(user);
mapper.select(id);
</code></pre>
<blockquote>
<p>&#x5355;&#x8868;&#x7B80;&#x5355;&#x6267;&#x884C; &#xFF08;&#x7B80;&#x4FBF;&#xFF0C;&#x5355;&#x8868;&#x64CD;&#x4F5C;&#xFF09;</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-comment">// &#x63D2;&#x5165;</span>
User user = <span class="hljs-keyword">new</span> User();
user.setId(KeyGenerateUtil.generateId());
user.setUserName(<span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>);
user.setPassword(<span class="hljs-string">&quot;123&quot;</span>);
user.setAge(<span class="hljs-number">20</span>);
<span class="hljs-comment">// &#x76F4;&#x63A5;&#x63D0;&#x4F9B;&#x5DF2;&#x7ECF;&#x8D4B;&#x503C;&#x7684;&#x5B9E;&#x4F53;&#x7C7B;&#xFF0C;&#x8981;&#x6C42;&#x5B9E;&#x4F53;&#x7C7B;&#x4F7F;&#x7528; @Table &#x6CE8;&#x89E3;</span>
SqlBox.insert(user);
SqlBox.insert(<span class="hljs-string">&quot;user&quot;</span>)
    .column(<span class="hljs-string">&quot;id&quot;</span>, id)
    .column(<span class="hljs-string">&quot;userName&quot;</span>, userName)
    .column(age, age).execute();

<span class="hljs-comment">// &#x66F4;&#x65B0;</span>
SqlBox.update(<span class="hljs-string">&quot;user&quot;</span>)
    .set(<span class="hljs-string">&quot;userName&quot;</span>, userName)
    .where().eq(<span class="hljs-string">&quot;id&quot;</span>, id).execute();

<span class="hljs-comment">// &#x5220;&#x9664;</span>
SqlBox.deleteById(User.class, <span class="hljs-string">&quot;123&quot;</span>);
SqlBox.delete(<span class="hljs-string">&quot;user&quot;</span>)
    .where().eq(<span class="hljs-string">&quot;id&quot;</span>, <span class="hljs-string">&quot;123&quot;</span>).execute();

<span class="hljs-comment">// &#x67E5;&#x8BE2;</span>
SqlBox.select(User.class)
    .where().eq(<span class="hljs-string">&quot;id&quot;</span>, id)
    .query(User.class);
Sqlbox.select(<span class="hljs-string">&quot;userName&quot;</span>, <span class="hljs-string">&quot;age&quot;</span>)
  .from(<span class="hljs-string">&quot;user&quot;</span>)
  .where().eq(<span class="hljs-string">&quot;id&quot;</span>, id)
  .query(User.class);
</code></pre>
<blockquote>
<p>&#x5206;&#x9875;&#x67E5;&#x8BE2;</p>
</blockquote>
<pre><code class="lang-java">Pager&lt;User&gt; users = A.fetchPage(sql, params, page, limit, User.class);
<span class="hljs-comment">// &#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x4E0D;&#x63D0;&#x4F9B; limit &#x53C2;&#x6570;&#xFF0C;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x7684; limit (10)&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5728; GlobalConfig &#x4E2D;&#x6216;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x914D;&#x7F6E;</span>
Pager&lt;User&gt; users = A.fetchPage(sql, params, page,  User.class);

<span class="hljs-comment">// Pager &#x4E2D;&#x7684;&#x53C2;&#x6570;&#x8BF4;&#x660E;</span>
</code></pre>
<blockquote>
<p>&#x6CE8;&#xFF1A;QueryFlow &#x7684;&#x6240;&#x6709;&#x6709;&#x5173;&#x6570;&#x636E;&#x5E93;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x90FD;&#x4E0D;&#x4F1A;&#x4E3B;&#x52A8;&#x5173;&#x95ED;&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;&#xFF0C;&#x9700;&#x8981;&#x5728;&#x624B;&#x52A8;&#x5173;&#x95ED;&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;&#x3002;&#x4E5F;&#x53EF;&#x4EE5;&#x5728;&#x5168;&#x5C40;&#x914D;&#x7F6E;&#x4E2D;&#x914D;&#x7F6E;&#x6CA1;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x64CD;&#x4F5C;&#x7ACB;&#x5373;&#x5173;&#x95ED;&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5; <code>GlobalConfig.closeAfterExecuted(true)</code> &#x3002;</p>
<p>&#x6279;&#x91CF;&#x64CD;&#x4F5C;</p>
</blockquote>
<pre><code class="lang-java">BatchStatement batch = A.createBatch()
<span class="hljs-keyword">int</span>[] rows = batch.add(sql)<span class="hljs-comment">// &#x6DFB;&#x52A0;&#x8981;&#x6267;&#x884C;&#x7684;SQL</span>
  .add(sql)
  .execute();
<span class="hljs-comment">// &#x6279;&#x91CF;&#x6267;&#x884C;&#x9700;&#x8981;&#x9884;&#x7F16;&#x8BD1;&#x7684; SQL</span>
PreparedBatchStatement pbs = A.prepareBatch(<span class="hljs-string">&quot;sql&quot;</span>);
<span class="hljs-comment">// &#x6DFB;&#x52A0;&#x53C2;&#x6570;&#xFF0C;&#x6700;&#x540E;&#x4F7F;&#x7528; add &#x65B9;&#x6CD5;&#xFF0C;&#x5C06;&#x53C2;&#x6570;&#x96C6;&#x5408;&#x6DFB;&#x52A0;&#x5230; PreparedStatement</span>
pbs.bind(<span class="hljs-string">&quot;a&quot;</span>).bind(<span class="hljs-string">&quot;b&quot;</span>).add();
<span class="hljs-comment">// &#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x64CD;&#x4F5C;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x65B9;&#x6CD5;&#x76F4;&#x63A5;&#x6DFB;&#x52A0;&#x53C2;&#x6570;</span>
pbs.add(Object... params);
<span class="hljs-comment">// &#x6216;&#x8005;</span>
pbs.add(List&lt;Object&gt; params);
</code></pre>
<blockquote>
<p>&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#x8C03;&#x7528;</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-comment">// &#x53EA;&#x6709;&#x8F93;&#x5165;&#x53C2;&#x6570;</span>
A.call(<span class="hljs-string">&quot;call test(?,?)&quot;</span>, <span class="hljs-string">&quot;A&quot;</span>, <span class="hljs-string">&quot;B&quot;</span>);
<span class="hljs-comment">// &#x6216;&#x8005;</span>
List&lt;Object&gt; params = <span class="hljs-keyword">new</span> ArrayList&lt;&gt;();
params.add(<span class="hljs-string">&quot;A&quot;</span>);
params.add(<span class="hljs-string">&quot;B&quot;</span>);
A.call(<span class="hljs-string">&quot;call test(?,?)&quot;</span>, params);

<span class="hljs-comment">// &#x5305;&#x542B;&#x8F93;&#x51FA;&#x53C2;&#x6570;</span>
OutParameters outParameters = A.createCall()
  .bind(<span class="hljs-string">&quot;A&quot;</span>)<span class="hljs-comment">// &#x8F93;&#x5165;&#x53C2;&#x6570;</span>
  .registerOutParameter(<span class="hljs-string">&quot;sum&quot;</span>, DataType.INTEGER)<span class="hljs-comment">// &#x6CE8;&#x518C;&#x8F93;&#x51FA;&#x53C2;&#x6570;</span>
  execute();
<span class="hljs-comment">// &#x83B7;&#x53D6;&#x6CE8;&#x518C;&#x7684;&#x8F93;&#x51FA;&#x53C2;&#x6570;&#x7684;&#x503C;</span>
<span class="hljs-keyword">int</span> sum = outParameters.getInteger(<span class="hljs-string">&quot;sum&quot;</span>);
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="install.html" class="navigation navigation-next navigation-unique" aria-label="Next page: 安装">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"快速开始","level":"1.2.1","depth":2,"next":{"title":"安装","level":"1.2.2","depth":2,"path":"introduction/install.md","ref":"introduction/install.md","articles":[]},"previous":{"title":"入门","level":"1.2","depth":1,"ref":"","articles":[{"title":"快速开始","level":"1.2.1","depth":2,"path":"introduction/quick-start.md","ref":"introduction/quick-start.md","articles":[]},{"title":"安装","level":"1.2.2","depth":2,"path":"introduction/install.md","ref":"introduction/install.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"introduction/quick-start.md","mtime":"2019-07-26T05:43:15.744Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-07-26T08:30:21.431Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

